//
//  VideoPlayerViewController.m
//  ExhibitForcePrototype
//
//  Created by Toma Popov on 12/5/12.
//  Copyright (c) 2012 Dilyana Todorova. All rights reserved.
//

#import "PlayVideoViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface PlayVideoViewController ()<UIAlertViewDelegate>
@property (strong) MPMoviePlayerController* player;
@end

@implementation PlayVideoViewController
@synthesize player;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"Starry Night";
    [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed)] ];
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonPressed)] ];
    
    
    NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
    NSURL *url = [NSURL fileURLWithPath:resourcePath];
    player = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [player prepareToPlay];
    //NSLog(@"(%f,%f)",self.view.bounds.size.width,self.view.bounds.size.height);
    player.view.frame = CGRectMake(0, 0, 540, 620);
    player.shouldAutoplay=NO;
    player.scalingMode = MPMovieScalingModeAspectFit;
    player.controlStyle = MPMovieControlStyleFullscreen;
    player.backgroundView.hidden = YES;
    //[player setFullscreen:YES animated:YES];
    [self.view addSubview:player.view];
    [player play];

}
-(void)addButtonPressed
{
    [[[UIAlertView alloc] initWithTitle:@"Add to Cart" message:@"The video was added to the cart." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] show];
    
}
-(void)cancelButtonPressed
{
    [[self.navigationController presentingViewController] dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [[self.navigationController presentingViewController] dismissViewControllerAnimated:YES completion:^{
        
    }];
}
@end
